package com.zr.WarehouseBelonging.controller;

import com.zr.WarehouseBelonging.pojo.*;
import com.zr.WarehouseBelonging.service.WarehouseBelongingService;
import com.zr.meiju.StatusEnum;
import com.zr.meiju.XiaLaVo;
import com.zr.util.AllRecords;
import com.zr.util.ResultBuildVo;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/6/13.
 */
@RestController
@CrossOrigin
@RequestMapping("WarehouseBelonging/")
public class WarehouseBelongingController {
    @Autowired
    private WarehouseBelongingService warehouseBelongingService;
    /**
     * 法人下拉框
     */
    @GetMapping("ByLegalPersonId/aaa")
    public Legalperson ByLegalPersonId(@RequestParam("id") Integer id){
        return warehouseBelongingService.ByLegalPersonId(id);
    }
    /**
     * 启用禁用下拉框
     */

    @GetMapping("xiala")
    public ResultVo<List<XiaLaVo>> queryXiaLa(){

        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        for (int i = 0; i< StatusEnum.values().length; i++){
            XiaLaVo xiaLaVo = new XiaLaVo();
            xiaLaVo.setValue(i);
            xiaLaVo.setLabel(StatusEnum.getName(i));
            xiaLaVoList.add(xiaLaVo);
        }
        return ResultBuildVo.success(xiaLaVoList);
    }

    /**
     * 修改状态
     * 表单验证
     */
    @PostMapping("updatestatus")
    public ResultVo updateState(@RequestBody @Valid DepotStatusVo depotStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return warehouseBelongingService.updateState(depotStatusVo);
    }
    /**
     * 分页查询
     */
    @PostMapping("queryPage")
    public ResultVo<AllRecords> queryPage(@RequestBody DepotSelectVo depotSelectVo){
        return warehouseBelongingService.queryPage(depotSelectVo);
    }

    /**
     * 查看的功能
     */
    @PostMapping("see")
    public ResultVo wareSee(@RequestBody WarehouseBeelongingSelectVo warehouseBeelongingSelectVo){
        return warehouseBelongingService.wareSee(warehouseBeelongingSelectVo);
    }

    /**
     * 库房明细的查询
     */
    @PostMapping("queryPageDepot")
    public ResultVo<AllRecords> queryPageDepot(@RequestBody DepotSelectVo depotSelectVo){
        return warehouseBelongingService.queryPageDepot(depotSelectVo);
    }

    /**
     * 根据库房的id查询库区
     */
    @GetMapping("/queryDepotarea")
    public List<Integer> queryDepotById(@RequestBody List<Integer> depotId){
        return warehouseBelongingService.queryDepotById(depotId);
    }

    /**
     * 根据库区的id查询库位
     */
    @GetMapping("/queryDepotposition")
    public List<Integer> queryDepotareaById(@RequestBody List<Integer> depotareaId){
        return warehouseBelongingService.queryDepotareaById(depotareaId);
    }

    /**
     * 新增接口
     */
    @PostMapping("addWarehouseBelonging")
    public ResultVo addWarehouseBelonging(@RequestBody @Valid WarehouseBelongingAddVo warehouseBelongingAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return warehouseBelongingService.addWarehouseBelonging(warehouseBelongingAddVo);
    }

}